package com.taptech.doufu.bean.personalcenter;

import java.lang.reflect.Field;

import org.json.JSONArray;
import org.json.JSONObject;


import com.taptech.doufu.bean.ActionMsgBean;
import com.taptech.doufu.bean.BaseBean;
import com.taptech.doufu.bean.GroupBriefBean;
import com.taptech.doufu.bean.HomeTopBean;
import com.taptech.doufu.bean.UserBean;
import com.taptech.doufu.bean.CommentDataBean;
import com.taptech.doufu.bean.ReplyDataBean;
import com.taptech.doufu.bean.GroupInfoBean;

@SuppressWarnings("serial")
public class PersonalNotifyBean extends BaseBean
{
	private String id;
	private UserBean from_user;
	private String content;
	private String add_time;
	private String is_read;
	private String op_type;
	private HomeTopBean article;
	private CommentDataBean comment;
	private ReplyDataBean reply;
	private ReplyDataBean to_reply;

	private String object_type;
	private String target_type;
	private TopicBean topic;
	
	private String subobject_id;
	private String object_id;

	public String getSubobject_id()
	{
		return subobject_id;
	}

	public void setSubobject_id(String subobject_id)
	{
		this.subobject_id = subobject_id;
	}

	public String getObject_id()
	{
		return object_id;
	}

	public void setObject_id(String object_id)
	{
		this.object_id = object_id;
	}

	public TopicBean getTopic()

	{
		return topic;
	}

	public void setTopic(TopicBean topic)

	{
		this.topic = topic;
	}

	public String getTarget_type()
	{
		return target_type;
	}

	public void setTarget_type(String target_type)
	{
		this.target_type = target_type;
	}

	public void setJson(JSONObject json)
	{
		try
		{
			Field fields[] = getClass().getDeclaredFields();
			String fieldName;
			Object value = null;

			for (Field field : fields)
			{
				field.setAccessible(true);
				fieldName = field.getName();
				// Log.i("TAG", "fieldName:"+fieldName);
				if (fieldName.equals("json"))
					continue;
				if (json.has(fieldName) && !json.isNull(fieldName))
				{
					if (fieldName.equalsIgnoreCase("comuBrief"))
					{
						JSONObject comObj = json.getJSONObject(fieldName);
						GroupBriefBean group = new GroupBriefBean();
						group.setJson(comObj);
						value = group;
					} else if (fieldName.equalsIgnoreCase("community"))
					{
						JSONObject userObj = json.getJSONObject(fieldName);
						GroupInfoBean community = new GroupInfoBean();
						community.setJson(userObj);
						value = community;
					} else if (fieldName.equalsIgnoreCase("user"))
					{
						JSONObject userObj = json.getJSONObject(fieldName);
						UserBean user = new UserBean();
						user.setJson(userObj);
						value = user;
					} else if (fieldName.equalsIgnoreCase("to_user"))
					{
						JSONObject userObj = json.getJSONObject(fieldName);
						UserBean user = new UserBean();
						user.setJson(userObj);
						value = user;
					} else if (fieldName.equalsIgnoreCase("from_user"))
					{
						JSONObject userObj = json.getJSONObject(fieldName);
						UserBean user = new UserBean();
						user.setJson(userObj);
						value = user;
					} else if (fieldName.equalsIgnoreCase("article"))
					{
						JSONObject jsonValue = json.getJSONObject(fieldName);
						HomeTopBean data = new HomeTopBean();
						data.setJson(jsonValue);
						value = data;

					} else if (fieldName.equalsIgnoreCase("comment"))
					{
						JSONObject jsonValue = json.getJSONObject(fieldName);
						CommentDataBean data = new CommentDataBean();
						data.setJson(jsonValue);
						value = data;

					} else if (fieldName.equalsIgnoreCase("reply") || fieldName.equalsIgnoreCase("to_reply"))
					{
						JSONObject jsonValue = json.getJSONObject(fieldName);
						ReplyDataBean data = new ReplyDataBean();
						data.setJson(jsonValue);
						value = data;
					} else if (fieldName.equalsIgnoreCase("actionMsg"))
					{
						JSONObject actionObj = json.getJSONObject(fieldName);
						ActionMsgBean action = new ActionMsgBean();
						action.setJson(actionObj);
						value = action;
					} else if (fieldName.equalsIgnoreCase("images"))
					{
						JSONArray jsonImages = json.getJSONArray(fieldName);
						value = initImages(jsonImages);
					} else if (fieldName.equalsIgnoreCase("result"))
					{
						JSONArray jsonResule = json.getJSONArray(fieldName);
						value = initResult(jsonResule);
					} else if (fieldName.equalsIgnoreCase("replies"))
					{
						JSONArray jsonResule = json.getJSONArray(fieldName);
						value = initReplies(jsonResule);
					} else if (fieldName.equalsIgnoreCase("topic"))
					{
						JSONObject jsonValue = json.getJSONObject(fieldName);
						TopicBean data = new TopicBean();
						data.setJson(jsonValue);
						value = data;

					} else
					{
						if (json.get(fieldName) instanceof String)
						{
							value = json.getString(fieldName);
						} else if (json.get(fieldName) instanceof Integer)
						{
							value = json.getString(fieldName);
						} else
						{
							value = "";
						}
					}
					field.set(this, value);
				}
			}
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public UserBean getFrom_user()
	{
		return from_user;
	}

	public void setFrom_user(UserBean from_user)
	{
		this.from_user = from_user;
	}

	public String getContent()
	{
		return content;
	}

	public void setContent(String content)
	{
		this.content = content;
	}

	public String getAdd_time()
	{
		return add_time;
	}

	public void setAdd_time(String add_time)
	{
		this.add_time = add_time;
	}

	public String getIs_read()
	{
		return is_read;
	}

	public void setIs_read(String is_read)
	{
		this.is_read = is_read;
	}

	public String getOp_type()
	{
		return op_type;
	}

	public void setOp_type(String op_type)
	{
		this.op_type = op_type;
	}

	public HomeTopBean getArticle()
	{
		return article;
	}

	public void setArticle(HomeTopBean article)
	{
		this.article = article;
	}

	public CommentDataBean getComment()
	{
		return comment;
	}

	public void setComment(CommentDataBean comment)
	{
		this.comment = comment;
	}

	public ReplyDataBean getReply()
	{
		return reply;
	}

	public void setReply(ReplyDataBean reply)
	{
		this.reply = reply;
	}

	public ReplyDataBean getTo_reply()
	{
		return to_reply;
	}

	public void setTo_reply(ReplyDataBean to_reply)
	{
		this.to_reply = to_reply;
	}

	public String getObject_type()
	{
		return object_type;
	}

	public void setObject_type(String object_type)
	{
		this.object_type = object_type;
	}

}
